package record.treeResult;

import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import record.consts.OperateType;

import java.util.List;

/**
 * @Package: com.record.treeResult
 * @ClassName: Item
 * @Author: wulongkai
 * @CreateTime: 2023/12/19 15:36
 * @Description:
 */
@Data
public class Item {
    String desc;
    String name;
    OperateType operateType;
    Object beforeValue;
    Object afterValue;
    List<Item> subItem;

    public void print() {
        print(null, 0);
    }

    private void print(String parentClassName, int level) {
        StringBuilder preSuf = new StringBuilder();
        for (int i = 0; i < level; i++) {
            preSuf.append("--");
        }
        String className = StringUtils.isEmpty(parentClassName) ? name : parentClassName + "." + name;
        System.out.println(preSuf + "desc:" + desc + "、class path:" + className);
        if (!CollectionUtils.isEmpty(subItem)) {
            for (Item item : subItem) {
                item.print(className, level + 1);
            }
        }
    }
}
